const { Schema, SchemaTypes } = require('../schema');
class Product extends Schema {
    PropertyModelDataTemplate () {
        return {
            areaId: { type: SchemaTypes.ObjectId, required: true },
            mainCategoryId: { type: SchemaTypes.ObjectId, required: false },
            subCategoryId: { type: SchemaTypes.ObjectId, required: false },
            createTime: { type: SchemaTypes.Number, required: true, default: require('../../module/tool/time').getCurrentTimestamp() },

            images: { type: SchemaTypes.Array, required: true },
            score: { type: SchemaTypes.String, required: true, default: '5.00' },
            title: { type: SchemaTypes.String, required: true },
            /** 产品类型**/
            productType: { type: SchemaTypes.Number, required: true },
            description: { type: SchemaTypes.String, required: true },
            tags: { type: SchemaTypes.Array, required: true, default: [] },
            /**
             * {
                "id": "981ddca0c20d",
                "title": "一包(400g)",
                "originalPrice": NumberInt('0'),
                "price": NumberInt('2000')
                "inventory":NumberInt('11') 库存占比
                }
             */
            skus: { type: SchemaTypes.Array, required: true },
            /**
             * {
                "title": "规格",
                "description": "400g*30包"
                },
             */
            specs: {
                type: SchemaTypes.Array,
                required: true
            },

            // ['肉类', '牛肉', '牛排']
            keyword: {
                type: SchemaTypes.Array,
                required: false
            },
            isEnable: {
                type: SchemaTypes.Boolean,
                required: true,
                default: false
            },
            isDelete: {
                type: SchemaTypes.Boolean,
                required: false,
                default: false
            },
            /** 库存**/
            inventory: {
                type: SchemaTypes.Number,
                required: true
            },
            /** 点击数**/
            hits: {
                type: SchemaTypes.Number,
                required: true,
                default: 0
            },
            /** 限购数量，针对秒杀商品**/
            quantityLimit: { type: SchemaTypes.Number, required: false },
            sort: {
                type: SchemaTypes.Number,
                required: true,
                default: 0
            }
        };
    }

    async findByIdProduct (productId) {
        return this.getModel().findById(productId);
    }
}

module.exports = Product;
